$(function(){
    laydate.render({
        elem: '[name=startDate]'
    });
    laydate.render({
        elem: '[name=endDate]'
    });
});
function search() {
   var param={};
   param.name=$("[name=name]").val();
   param.startDate=$("[name=startDate]").val();
   param.endDate=$("[name=endDate]").val();
    $("#userTb").bootstrapTable("refresh",{query:param});
}
function queryParams(param){
    param.name=$("[name=name]").val();
    param.startDate=$("[name=startDate]").val();
    param.endDate=$("[name=endDate]").val();
    return param;
}
$(document).ready(function(){
    $("#grant").dialog({
        title:"用户授权",
        btnName:"确认授权",
        btnBind:function(){
            var rows01=$("#userTb").bootstrapTable("getSelections");
            var rows02=$("#roleTb").bootstrapTable("getSelections");
            var param="userId="+rows01[0].id+"&roleId="+rows02[0].id;
            $.post(ctx+"sys/user/grant",param,function(msg){
                toastr.warning("信息提示",msg);
                $("#grant").dialog("close");
                $("#userTb").bootstrapTable("refresh");
            },'text');
        }
    });
});
function prepareGrant(){
    var rows=$("#userTb").bootstrapTable("getSelections");
    if(rows.length==0){
        swal({
            title:'信息提示',
            text:"请选择一项待授权！",
            type:"warning",
            confirmButtonText:"确定"
        });
        return;
    }
    var roleId=rows[0].roleId;
    $("#roleTb").bootstrapTable("checkBy",{field:"id",values:[roleId]});
    $("#grant").dialog("open");



}
$(function(){
    $.getJSON(ctx+"sys/role/list",function(arr){
        $(arr).each(function(){
            var $opt=$("<option/>");
            $opt.html(this.name);
            $opt.val(this.id);
            $opt.appendTo("[name=roleId]");
        });
    });
});

    $(document).ready(function() {
        $('[name=note]').summernote({
            height:150,
            placeholder:"请输入备注信息.."
        });
    });

    $(function(){
        $("#add").dialog({
            title:"添加用户",
            btnName:"确定",
            btnBind:function(){
                var param=$("#add form").serialize();
                 param=param+"&note="+$("[name=note]").summernote("code");
                 $.post(ctx+"sys/user/add",param,function(msg){
                    toastr.warning("信息提示",msg);
                    $("#add").dialog("close");
                    $("#userTb").bootstrapTable("refresh");
                 },'text');
            }
        });
    });
function prepareAdd(){
    $("#add").dialog("open");
}